import os
from threading import Thread

PROG = 'CodeCraft-2022'

log_path = '../logs/'

def runner(opt: str, log_name):
    os.system('./' + PROG + ' ' + opt + ' > ' + log_path + log_name)

if __name__=='__main__':
    option_file = 'option.txt'
    options = None
    with open(option_file, 'r') as f:
        options = f.read().splitlines()

    os.chdir('bin')
    
    os.makedirs(log_path, exist_ok=True)

    n_threads = len(options)
    threads = [Thread(target=runner, args=(opt, f'__{idx}.log')) for idx, opt in enumerate(options)]
    
    for t in threads:
        t.start()
    
    for t in threads:
        t.join()

    print('finished')